using System.Collections.Generic;

using com.tc.zigbee.zcl;

using com.tc.util;
namespace com.tc.zigbee.zcl
{
    public class ZclRawCommand
    {

        byte frameControl;

        public byte FrameControl
        {
            get { return frameControl; }
            set { frameControl = value; }
        }
        byte[] manufactureCode;

        public byte[] ManufactureCode
        {
            get { return manufactureCode; }
            set { manufactureCode = value; }
        }
        byte transactionSnum;

        public byte TransactionSnum
        {
            get { return transactionSnum; }
            set { transactionSnum = value; }
        }
        byte commandIdentifier;

        public byte CommandIdentifier
        {
            get { return commandIdentifier; }
            set { commandIdentifier = value; }
        }
        byte[] payload;

        public byte[] Payload
        {
            get { return payload; }
            set { payload = value; }
        }
        public byte[] frame()
        {
            int length = 1 + (manufactureCode == null ? 0 : 2) + 2 + (payload == null ? 0 : payload.Length);
            byte[] f = new byte[length];
            f[0] = FrameControl;
            int ind = 1;
            if (manufactureCode != null)
            {
                f[1] = manufactureCode[0];
                f[2] = manufactureCode[1];
                ind = 3;
            }
            f[ind++] = transactionSnum;
            f[ind++] = commandIdentifier;
            for (int i = 0; ind < length; ind++, i++)
                f[ind] = payload[i];
            return f;
        }
        public ZclRawCommand(byte[] data)
        {
            int i = 0;
            frameControl = data[i++];
            byte menu = (byte)(0x04 & frameControl);
            if (menu == 4)
            {
                manufactureCode[0] = data[i++];
                manufactureCode[1] = data[i++];
            }
            transactionSnum = data[i++];
            commandIdentifier = data[i++];
            payload = new byte[data.Length - i];
            int s = i;
            for (; i < data.Length; i++)
                payload[i - s] = data[i];
        }
        public ZclRawCommand()
        {
            // TODO Auto-generated constructor stub
        }


    }
}